package org.robby.hbase.cdr.filter;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.HTablePool;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
import org.apache.hadoop.hbase.filter.SubstringComparator;
import org.apache.hadoop.hbase.util.Bytes;
import org.robby.hbase.cdr.HbaseCdrIF;

public class CustomFilterRun {
	
	private static HTablePool pool;
	public static HbaseCdrIF hbsase = null;
	private static String tab_cdr_name = "tab_cdr2";

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		HBaseConfiguration config = new HBaseConfiguration();
		config.set("hbase.zookeeper.quorum", "hadoop.main");// 连接到远程服务上
		pool = new HTablePool(config, 1000);

		Scan s = new Scan();
		
		Filter filter = new CustomFilter("13900000062_13900009377_20120811062821");
		
		
		s.setFilter(filter);
		HTableInterface tab_cdr2 = pool.getTable(tab_cdr_name);
		ResultScanner rs = tab_cdr2.getScanner(s);

		for (Result r : rs) {
			String out = Bytes.toString(r.getRow()) + "\t";
			byte[] data = r.getValue(Bytes.toBytes("data"), Bytes.toBytes("oaddr"));
			out += Bytes.toString(data) + "\t";
			data = r.getValue(Bytes.toBytes("data"), Bytes.toBytes("oareacode"));
			out += Bytes.toString(data) + "\t";
			data = r.getValue(Bytes.toBytes("data"), Bytes.toBytes("daddr"));
			out += Bytes.toString(data) + "\t";
			data = r.getValue(Bytes.toBytes("data"), Bytes.toBytes("dareacode"));
			out += Bytes.toString(data) + "\t";
			data = r.getValue(Bytes.toBytes("data"), Bytes.toBytes("ts"));
			out += Bytes.toString(data) + "\t";
			data = r.getValue(Bytes.toBytes("data"), Bytes.toBytes("type"));
			out += Bytes.toString(data) + "\t";
			System.out.println(out);
		}

	}
}
